﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PegasCompany.Data;
using PegasCompany.SiteMembership;
using PegasCompany.Tools;

namespace PegasCompany.Master
{
    public partial class Common : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                hlAdminPanel.Visible = MembershipHelper.MembershipService.IsAuthorizedRequest;

                FillMenu();
                FillYearList();
                FillLastNews();
            }
        }

        private void FillMenu()
        {
            List<SiteMenuItem> smiList = SiteMenuItem.GetMenuItemsTree(MembershipHelper.MembershipService.IsAuthorizedRequest);
            rptMainMenu.DataSource = smiList;
            rptMainMenu.DataBind();
        }

        private void FillYearList()
        {
            IOrderedEnumerable<int> lYearList = SiteContent.ListAllContentYear((int)EnumHelper.ListContentType.News).OrderByDescending(i => i);
            rptArchive.DataSource = lYearList;
            rptArchive.DataBind();
        }

        private void FillLastNews()
        {
            List<SiteContent> lLastNews = SiteContent.ListAllContent((int)EnumHelper.ListContentType.News, null, 3);
            {
                if (lLastNews != null)
                {
                    rptNews.DataSource = lLastNews;
                    rptNews.DataBind();
                }
            }
        }
    }
}